package cn.hrfax.stf.sdk.controller;

import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import cn.hrfax.stf.sdk.model.*;
import org.springframework.web.bind.annotation.*;

import cn.hrfax.stf.sdk.integration.remote.TradeRemote;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * @author yongSen.wang
 * @date 2020/6/15 15:27
 */
@RestController
@RequestMapping("/trade")
@Api(value = "短融交易controller", tags = { "短融交易操作接口" })
public class TradeController {

    @Resource
    private TradeRemote tradeRemote;

    @PostMapping("/applyCredit")
    @ApiOperation("E分期授信申请")
    public RemoteResponse applyCredit(@RequestBody @ApiParam(name = "E分期授信申请对象", value = "传入json格式", required = true) ApplyCreditParams params) {
        return tradeRemote.applyCredit(params);
    }

    @PostMapping("/stagesInput")
    @ApiOperation("E分期进件")
    public RemoteResponse stagesInput(@RequestBody @ApiParam(name = "E分期进件对象", value = "传入json格式", required = true) StagesInputParams params) {
        return tradeRemote.stagesInput(params);
    }

    @PostMapping("/apply")
    @ApiOperation("申请短融")
    public RemoteResponse apply(@RequestBody @ApiParam(name = "申请短融对象", value = "传入json格式", required = true) ApplyTradeParams params) {
        return tradeRemote.applyTrade(params);
    }

    @PostMapping("/confirmation")
    @ApiOperation("信息确认")
    public RemoteResponse confirmation(@RequestBody @ApiParam(name = "信息确认对象", value = "传入json格式", required = true) ConfirmationParams params) {
        return tradeRemote.confirmation(params);
    }

    @PostMapping("/queryTradeResult")
    @ApiOperation("短融交易结果查询")
    public RemoteResponse queryTradeResult(@RequestBody @ApiParam(name = "结果查询对象", value = "传入json格式", required = true) QueryTradeParams params) {
        return tradeRemote.queryTradeResult(params);
    }

    @PostMapping(value = "/queryOrganConfig")
    @ResponseBody
    @ApiOperation(value = "查询机构配置信息")
    public RemoteResponse queryOrganConfig(HttpServletRequest request) throws IOException {
        return tradeRemote.queryOrganConfig();
    }

    @PostMapping("/openCard")
    @ApiOperation("开卡")
    public RemoteResponse openCard(@RequestBody @ApiParam(name = "开卡对象", value = "传入json格式", required = true) OpenCardParams params) {
        return tradeRemote.openCard(params);
    }

}
